import table from '@/components/dt/table/render.js'

function columns(_this) {
  return [{
    field: 'companyDesc',
    title: '公司范围',
    slots: {
      default: (params, h) => {
        return table.cell.text(h, {
          value: params.row.companyDesc
        })
      }
    }
  },
  {
    field: 'createTime',
    title: '创建时间',
    width: 300
  },
  {
    field: 'handles',
    title: '操作',
    width: 300,
    cell: (item) => {
      let btn = []
      btn.push({
        title: '查看',
        event: 'oncheck',
      })
      btn.push({
        title: '编辑',
        event: 'onEdit',
        code: '0204050300',
      })
      btn.push({
        title: '删除',
        event: 'onDelete',
        code: '0204050400'
      })
      return { btn }
    }
  }]
}

function processNodeColumns(_this, length) {
  let vm = _this
  return [{
      type: 'index',
      title: '流程节点',
      width: 150,
    },
    {
      key: 'reviewerType',
      title: '审核人类型',
      minWidth: 200,
      slot: 'reviewerType'
    },
    {
      key: 'reviewerId',
      title: '审核人',
      minWidth: 180,
      slot: 'reviewerId',
      renderHeader: (h, params) => {
        return h('div', [
          h('span', {}, '审核人'),
          h('Tooltip', {
            props: {
              content: '仅审核人类型为角色时，若对应的角色没有关联人员，对应节点自动审核通过！',
              placement: "right",
              transfer: true
            }
          }, [h('Icon', {
            props: {
              type: 'ios-help-circle-outline',
              size: '16',
            },
            style: {
              marginLeft: '5px',
            },
          }), ])
        ])
      },
    },

    {
      key: 'handles',
      title: '操作',
      width: 200,
      render: (h, params) => {
        return h('div', [
          h(
            'a', {
              style: {
                cursor: 'pointer',
                marginRight: '7px',
                display: length == 1 ? 'none' : 'inline-block'
              },
              on: {
                click: (e) => {
                  e.stopPropagation()
                  vm.delete(params.row)
                },
              },
            },
            '删除'
          ),
          h(
            'a', {
              style: {
                cursor: 'pointer',
                marginRight: '7px',
                display: params.row._index == 0 ? 'none' : 'inline-block'
              },
              on: {
                click: (e) => {
                  e.stopPropagation()
                  vm.upItems(params.row._index)
                },
              },
            },
            '上移'
          ),
          h(
            'a', {
              style: {
                cursor: 'pointer',
                display: params.row._index == length - 1 ? 'none' : 'inline-block'
              },
              on: {
                click: (e) => {
                  e.stopPropagation()
                  vm.downItems(params.row._index)
                },
              },
            },
            '下移'
          )
        ])
      },
    }
  ]
}

function checkProcessColumns(_this, length) {
  let vm = _this
  return [{
    type: 'index',
    title: '流程节点',
    width: 120,
  },
  {
    key: 'reviewerType',
    title: '审核人类型',
    minWidth: 140,
    slots: {
      default: (params, h) => {
        return table.cell.text(h, {
          value: params.row.reviewerType == 1 ? '角色' : '人员'
        })
      }
    }
  },
  {
    key: 'reviewerDesc',
    title: '审核人',
    minWidth: 180,
    slots: {
      default: (params, h) => {
        return table.cell.text(h, {
          value: params.row.reviewerDesc
        })
      }
    }
  }, ]
}

function reviewerTypeList() {
  return [{
    key: 1,
    vlaue: '角色'
  },
  {
    key: 2,
    vlaue: '人员'
  }, ]
}
export default {
  columns,
  processNodeColumns,
  checkProcessColumns,
  reviewerTypeList
}